package cn.lzd.mvp.base.struct;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import androidx.annotation.CallSuper;
import androidx.appcompat.app.AppCompatActivity;
import butterknife.ButterKnife;

/**
 * FileName: BaseActivity
 * Founder:
 * Create Date:
 * Email:
 * Profile: Base Activity  基类
 */
public abstract class BaseActivity<P extends IPresenter> extends AppCompatActivity implements IView, InitialPro<P> {
    protected P mPresenter;
    protected View mContentView;

    @SuppressLint("InflateParams")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Event后，在后台能接到消息; 要用Manager里面的eventMManager
        mPresenter = initPresenter();//被 泛型的某一个Presenter来初始化IPresenter  在Activity中
        mContentView = LayoutInflater.from(this).inflate(getContentViewId(), null, false);
        setContentView(mContentView);
        ButterKnife.bind(this, mContentView);
        initView();
        initData();
    }

    @CallSuper
    protected void initData() {
        mPresenter.initDataReq();
    }

    //解绑
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroy();
            mPresenter = null;
        }
    }
}
